/*
 * TimeIncremental.java
 *
 * Created on 8 de mayo de 2006, 09:25 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package inc.jmc.cyberboard;
import java.util.*;

import inc.jmc.cyberboard.common.NumFormat;
import inc.jmc.cyberboard.log.*;
import org.apache.log4j.Logger;
/**
 *
 * @author vaiojmc
 */
public class TimeIncremental implements java.io.Serializable{

    /**
	 * 
	 */
	private static final long serialVersionUID = 4312315024155512271L;
	static Logger logger = Logger.getLogger(TimeIncremental.class.getName());
    Date fechaFinal=new Date();
    
    private java.text.NumberFormat nf2;
        
    int hh;
    int mm;
    int ss;
    /** Creates a new instance of TimeIncremental */
    public TimeIncremental() {
        nf2=NumFormat.dos_Enteros_00;
    }
    void setTime(int hh,int mm, int ss)
    {
        this.hh=hh;
        this.mm=mm;
        this.ss=ss;
    }
    public void addSecond(int i)
    {
        ss+=i;
        if(ss/60>0)
        {
        int aux=ss/60;
        mm+=aux;
        ss%=60;
        if(mm/60>0)
          {
            int aux1=mm/60;
            hh+=aux1;
            mm%=60;
          }
        }
    }
    public void addTimeIncremental(TimeIncremental operando)
    {
        int segundos = (int )operando.equivalenteSegundos();
        this.addSecond(segundos);
    }
    public int getHour()
    {
        return hh;
    }
    public int getMinute()
    {
        return mm;
    }
    public int getSecond()
    {
        return ss;
    }
    public String toString()
    {
        nf2.setMinimumIntegerDigits(2);
        StringBuffer sbf=new StringBuffer();
        sbf.append(nf2.format(hh));
        sbf.append(":");
        sbf.append(nf2.format(mm));
        sbf.append(":");
        sbf.append(nf2.format(ss));
        return sbf.toString();
    
    }
    public long equivalenteSegundos()
    {
        return hh*60*60+mm*60+ss;
    }
    
    public long equivalenteMinutos()
    {
        return hh*60+mm;
    }
    public void calculaDifferencia(long milis)
    {
    	
    	long time = System.currentTimeMillis();
    	long time2=time-milis;
    	fechaFinal.setTime(time2);
    	String diferencia1 = NumFormat.sdf_hh_mm_ss_DiferenciaCronometros.format(fechaFinal);
    	this.hh=Integer.parseInt(diferencia1.split(":")[0]);
    	this.mm=Integer.parseInt(diferencia1.split(":")[1]);
    	this.ss=Integer.parseInt(diferencia1.split(":")[2]);
    	
    }
    
    public static void main(String args[])
    {
        TimeIncremental inc=new TimeIncremental();
        /*inc.setTime(0,0,0);
        for(int i=0;i<7400;++i)
        {
            inc.addSecond(333);
            logger.info(inc);
        
        }*/
        long time111 = System.currentTimeMillis();
        inc.calculaDifferencia(time111);
    
    }
}
